﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using HA.MT3DMS.DomainLayer;
namespace HA.ModFlow.Controls.MT3DMSWindows
{
    /// <summary>
    /// winPolygonConc.xaml 的交互逻辑
    /// </summary>
    public partial class winPolygonConc : Window
    {
        public winPolygonConc( List<SPPolygonConc>arry)
        {
            InitializeComponent();
            this._arrySPPolygonConc = new List<SPPolygonConc>();
            for (int i = 0; i < arry.Count; i++)
            {
                this._arrySPPolygonConc.Add((SPPolygonConc) arry[i].Clone());
            }

            this.cboIndex.Items.Clear();
            List<int> arryIndex = new List<int>();
            for (int i = 0; i < arry.Count; i++)
            {
                arryIndex.Add(i + 1);
            }
            this.cboIndex.ItemsSource = arryIndex;
            this.cboIndex.SelectedIndex = 0;
        }


        List<SPPolygonConc> _arrySPPolygonConc;

        public List<SPPolygonConc> ArrySPPolygonConc
        {
            get { return _arrySPPolygonConc; }
            set { _arrySPPolygonConc = value; }
        }
        private void cboIndex_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int index=this .cboIndex .SelectedIndex ;
            if (index != -1)
            {
                if (index == 0)
                {
                    _arrySPPolygonConc[index].UsePrecious = false;
                    this.chkUsePre.IsEnabled = false;
                }
                else
                {
                    this.chkUsePre.IsEnabled = true;
                }
                if (_arrySPPolygonConc[index].UsePrecious)
                {
                    this.chkUsePre.IsChecked = true;
                    this.myArray.IsEnabled = false;
                }
                else
                {
                    this.chkUsePre.IsChecked = false ;
                    this.myArray.IsEnabled = true ;
                }
              

                myArray.dgData.ItemsSource = PCGridArrayLayer<double>.GetBindable2DArray<double>(_arrySPPolygonConc[index].Conc);
                this.myArray.SetDoubleData(_arrySPPolygonConc[index].Conc);
            }
        }

        private void chkUsePre_Click(object sender, RoutedEventArgs e)
        {
            if (this.chkUsePre.IsChecked.Value)
            {
                this._arrySPPolygonConc[this.cboIndex.SelectedIndex].UsePrecious = true;
                this.myArray.IsEnabled = false;
            }
            else
            {
                this._arrySPPolygonConc[this.cboIndex.SelectedIndex].UsePrecious = false;
                this.myArray.IsEnabled = true ;
            }
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            this.Close();
        }

        private void btnCancal_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btnReset_Click(object sender, RoutedEventArgs e)
        {
            int index = this.cboIndex.SelectedIndex;
            if (index != -1)
            {
                HA.ModFlow.Controls.UserControls.winResetValue winReset = new HA.ModFlow.Controls.UserControls.winResetValue(DataType.DOUBLE);
                winReset.Owner = this;
                winReset.ResizeMode = System.Windows.ResizeMode.NoResize;
                winReset.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
                winReset.ShowInTaskbar = false;
                if (winReset.ShowDialog().Value)
                {
                    _arrySPPolygonConc[index].Conc = ResetData(_arrySPPolygonConc[index].Conc, Convert .ToDouble ( winReset.txtResetValue.Text));
                    myArray.dgData.ItemsSource = PCGridArrayLayer<double>.GetBindable2DArray<double>(_arrySPPolygonConc[index].Conc);
                    this.myArray.SetDoubleData(_arrySPPolygonConc[index].Conc);
                }
            }
        }

        private double[,] ResetData(double[,]da,double value)
        {
            double[,] data = new double[da.GetLength(0), da.GetLength(1)];
            for (int i = 0; i < data.GetLength(0); i++)
            {
                for (int j = 0; j < data.GetLength(1); j++)
                {
                    data[i, j] = value;
                }
            }
            return data;
        }

      
    }
}
